package com.kun.service_edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kun.service_edu.entity.EduCourse;
import com.kun.service_edu.entity.EduTeacher;
import com.kun.service_edu.service.EduCourseService;
import com.kun.service_edu.service.EduTeacherService;
import com.kun.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/service_edu/indexFront")
@CrossOrigin
public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;
    @GetMapping("index")
    @Cacheable(key = "'indexList'",value = "index")
    public R findCourse(){
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("view_count");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> eduCourseList = courseService.list(courseQueryWrapper);

        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("id");
        eduTeacherQueryWrapper.last("limit 4");
        List<EduTeacher> eduTeacherList  = teacherService.list(eduTeacherQueryWrapper);
        return R.ok().data("eduCourseList",eduCourseList).data("eduTeacherList",eduTeacherList);
    }
}
